<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="pg" uri="http://jsptags.com/tags/navigation/pager" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript">
<!--
jQuery.trimCommas = function(text) {
    return text == null ?
        "" :
        text.toString().replace(/^[\s,]+|[\s,]+$/g, "");
};

function addQuestion()
{
	var question_serial = $('input[name="question_serial"]').val();
	var question_tag = $('input[name="question_tag"]').val();
	var question_title = $('textarea[name=question_title]').val();
	question_serial = $.trimCommas(question_serial);
	question_tag = $.trimCommas(question_tag);
	question_title = $.trimCommas(question_title);
	$('input[name="cPage"]').val(${pagination.currentPage});
	if (question_serial=="" || question_tag=="" || question_title=="") {
		showError("请填写完整");
	}
	else {
		$("#add_form").submit();
	}
}

function showError(message) 
{
	$().Message({type:'error', time:2000,text:message, target:"#errorDiv", click:true});	
}

/**
 * 删除试题确认 
 */
function delConfirm(questionID)
{
	var r=confirm("确认要删除试题[" + questionID + "]吗");
	if (r==true)
	{
		window.location.href = "<%=basePath%>backend/backend.do?action=deleteQuestion&question_id=" + questionID + "&cPage=${pagination.currentPage}";
	}
	else
	{
	}
}

//-->
</script>
<div id="submenu">
	<div class="modules_left">
		<div class="module buttons">
			<a href="" class="dropdown_button"><small class="icon plus"></small><span>新建试题</span></a>
			<div class="dropdown">
				<div class="arrow"></div>
				<div class="content">
					<form id='add_form' name='add_form' action="<%=basePath%>backend/backend.do?action=addQuestion" method='POST'>
						<input type="hidden" id="cPage" name="cPage">
						<p>
							<div id="errorDiv">
							</div>
						</p>
						<p>
							<label for="simple_input">试题序号:</label>
							<input type="text" id="question_serial" name="question_serial" value="" class="text w_20" />
						</p>
						<p class="small"></p>
						<br />
						<p>
							<label for="simple_input">试题标签:</label>
							<input type="text" id="question_tag" name="question_tag" value="" class="text w_20" />
						</p>
						<br />
						<p>
							<label for="simple_input">试题题干:</label>
							<textarea id="question_title" name="question_title" rows="10" cols="35"></textarea>
						</p>
						<p class="small"></p>
						
					</form>
					<a href="javascript:addQuestion();" class="button green right"><small class="icon check"></small><span>Save</span></a>
					<a class="button red mr right close"><small class="icon cross"></small><span>Close</span></a>
					<div class="clear"></div>
				</div>
			</div>
		</div>
	</div>
</div>

<div class="col w10 last">
	<div class="content">
		<table>
			<tr>
<!-- 				<th width="2%" class="checkbox"><input type="checkbox" name="checkbox" /></th> -->
				<th width="60%">试题名称</th>
				<th width="10%">描述</th>
				<th width="10%">状态</th>
				<th width="20%" align="right">操作</th>
			</tr>
			<c:forEach var="question" items="${pagination.items}">
				<tr id="id_1">
<!-- 					<td class="checkbox"><input type="checkbox" name="checkbox" /></td> -->
					<td><c:out value="${question.questionSummary}" /></td>
					<td><c:out value="${question.questionSerial}" /></td>
					<td>
						<c:choose>
							<c:when test="${question.questionStatus == '0'}">
								<img src="<%=basePath%>images/user-offline.png" />
							</c:when>
							<c:when test="${question.questionStatus == '1'}">
								<img src="<%=basePath%>images/user-online.png" />
							</c:when>
						</c:choose>
					</td>
					<td>
						<a href="<%=basePath%>backend/backend.do?action=viewQuestion&question_id=${question.id}"><span>查看</span></a>
						<c:choose>
							<c:when test="${question.questionStatus == '0'}">
								<a href="<%=basePath%>backend/backend.do?action=publishQuestion&question_id=${question.id}&flag=1&cPage=${pagination.currentPage}"><span>发布</span></a>
							</c:when>
							<c:when test="${question.questionStatus == '1'}">
								<a href="<%=basePath%>backend/backend.do?action=publishQuestion&question_id=${question.id}&flag=0&cPage=${pagination.currentPage}"><span>取消发布</span></a>
							</c:when>
						</c:choose>
						<a href="javascript:delConfirm('${question.id}');"><span>删除</span></a>
					</td>
				</tr>
			</c:forEach>
			<tr>
				 <td colspan="3" style="text-align: center;">
				 	共有${pagination.totalPages}页,当前是第${pagination.currentPage}页, ${pagination.totalCount}条记录
					<a href="<%=basePath%>backend/${pagination.actionUrl}&toPage=0">首页</a>
					<a href="<%=basePath%>backend/${pagination.actionUrl}&toPage=${pagination.currentPage - 1}">上一页</a>
					跳转到第 <select name="pageNumber" onchange="gotoSelectedPage();">
					    <c:forEach begin="1" end="${pagination.totalPages}" step="1" var="pageIndex">  
					        <c:choose>
					            <c:when test="${pageIndex eq currentPage}">
					                <option value="${pageIndex}" selected="selected">${pageIndex}</option>  
					            </c:when>
					            <c:otherwise>
					                <option value="${pageIndex}">${pageIndex}</option>  
					            </c:otherwise>  
					        </c:choose>
					    </c:forEach>
					    </select>页
					<a href="<%=basePath%>backend/${pagination.actionUrl}&toPage=${pagination.currentPage + 1}">下一页</a>
					<a href="<%=basePath%>backend/${pagination.actionUrl}&toPage=${pagination.totalPages}">尾页</a>
				</td>
			</tr>
		</table>
		
	</div>							
</div>
